package com.enen.demo.web.controller;

import com.enen.demo.bean.Category;
import com.enen.demo.service.ICategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/category")
@RestController
@Api(description = "栏目管理")
public class CategoryController {
    @Autowired
    private ICategoryService service;

    @PostMapping("/saveOrUpdate")
    @ApiOperation("保存或更新栏目信息")
    @ApiImplicitParam(value = "")
    public String saveOrUpdate(Category category){
        service.saveOrUpdate(category);
        return "保存成功";
    }

    @GetMapping("/findAll")
    @ApiOperation("查询所有栏目信息")
    public List<Category> findAll(){
        return  service.findAll();
    }

    @GetMapping("/findCategory")
    @ApiOperation("查询栏目信息")
    @ApiImplicitParam(name = "id",value = "栏目id",required = true,paramType = "query",dataType = "long")
    public Category findCategoryById(long id){
        return service.findCategoryById(id);
    }

    @DeleteMapping("/removeCategory")
    @ApiOperation("删除的栏目信息")
    public String removeCategory(long id){
        service.removeCategory(id);
        return "删除成功";
    }

}
